package com.mc2.docapp.disabilityassessmenttool.LowerLimb;

import io.realm.RealmObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class C_llca_ankleFoot extends RealmObject {
    private LLCustDataType plantar_dorsiflection_arc = new LLCustDataType();
    private LLCustDataType inversion_eversion = new LLCustDataType();
    private LLInnerCalculations inner_calculations = new LLInnerCalculations();

    public void calc(C_llca_ankleFoot c_llca_ankleFoot) {
        double a = c_llca_ankleFoot.getPlantar_dorsiflection_arc().getActual_right();
        double b = c_llca_ankleFoot.getInversion_eversion().getActual_right();

        double pa = perc(a, c_llca_ankleFoot.getPlantar_dorsiflection_arc().getNormal());
        double pb = perc(b, c_llca_ankleFoot.getInversion_eversion().getNormal());

        double x = (pa + pb) / 2.0;
        c_llca_ankleFoot.getPlantar_dorsiflection_arc().setPerc_loss_right(pa);
        c_llca_ankleFoot.getInversion_eversion().setPerc_loss_right(pb);

        a = c_llca_ankleFoot.getPlantar_dorsiflection_arc().getActual_left();
        b = c_llca_ankleFoot.getInversion_eversion().getActual_left();
        pa = perc(a, c_llca_ankleFoot.getPlantar_dorsiflection_arc().getNormal());
        pb = perc(b, c_llca_ankleFoot.getInversion_eversion().getNormal());
        double y = (pa + pb ) / 2.0;
        c_llca_ankleFoot.getPlantar_dorsiflection_arc().setPerc_loss_left(pa);
        c_llca_ankleFoot.getInversion_eversion().setPerc_loss_left(pb);

        c_llca_ankleFoot.setInner_calculations(new LLInnerCalculations(
                x,
                y,
                x * 0.2,
                y * 0.2
        ));
    }

    private double perc(double a, double normal) {
        return ((normal - a) * 100d) / (normal + 0d);
    }

}
